package com.sunlands.deskmate.message.handler.receiver.impl;

import com.sunlands.deskmate.config.RabbitMqConfig;
import com.sunlands.deskmate.message.entity.Messages;
import com.sunlands.deskmate.message.handler.receiver.Receiver;
import com.sunlands.deskmate.utils.IdGenerator;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static com.sunlands.deskmate.config.RabbitMqConfig.EXCHANGE_STORAGE;


/**
 * @author anjunling@sunlands.com
 */
@Slf4j
@Component
public class LivePersonalMessageReceiver implements Receiver {

    @Override
    public void receive(Channel channel, Messages message) {
        log.info("连麦房间私人消息 message = {}", message);
        Long id = IdGenerator.id();
        message.setAckId(id);
        message.setId(id.toString());
        message.setRealToId(Long.parseLong(message.getFromUserId()));
        rabbitTemplate.convertAndSend(EXCHANGE_STORAGE, rabbitMqConfig.getEnv(), message);
        log.info("发送消息到MQ = {} message = {}",EXCHANGE_STORAGE, message);
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RabbitMqConfig rabbitMqConfig;

}
